package com.hmall.api.config;

import com.hmall.common.utils.UserContext;
import feign.Logger;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    // 设置feign日志级别为full
    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }


    //feign请求拦截器
    @Bean
    public feign.RequestInterceptor requestInterceptor() {
        return new feign.RequestInterceptor() {
            @Override
            public void apply(feign.RequestTemplate template) {
                // 添加请求头信息
               // template.header("token", "123456");
                Long userId = UserContext.getUser();
                if (userId != null || userId != 0) {
                    template.header("user-info", userId.toString());
                }
            }
        };
    }


}
